package com.warehouse_management.market.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.warehouse_management.config.PageModel;
import com.warehouse_management.market.dao.IMarketDao;
import com.warehouse_management.market.model.Custom;
import com.warehouse_management.market.model.CustomCondition;
import com.warehouse_management.market.service.IMarketService;
import com.warehouse_management.system.model.Job;
import com.warehouse_management.login.model.Users;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class ImplMarketService implements IMarketService {

    @Autowired
    private IMarketDao marketDao;

    public IMarketDao getMarketDao() {
        return marketDao;
    }

    public void setMarketDao(IMarketDao marketDao) {
        this.marketDao = marketDao;
    }

    @Override
    public List<Custom> queryAllCustom() {
        return marketDao.queryAllCustom();
    }

    @Override
    public Custom queryOneCustom(CustomCondition customCondition) {
        return marketDao.queryOneCustom(customCondition);
    }

    @Override
    public List<Custom> queryAllCustomByCondition(CustomCondition condition) {
        return marketDao.queryAllCustomByCondition(condition);
    }

    @Override
    public int updateMarketCustomByState(CustomCondition customCondition){
        return marketDao.updateMarketCustomByState(customCondition);
    }

    @Override
    public int updateCustom(CustomCondition customCondition) {
        return marketDao.updateCustom(customCondition);
    }

    @Override
    public List<Job> queryAllJob() {
        return marketDao.queryAllJob();
    }

    @Override
    public List<Users> queryUserByJob(Job job) {
        return marketDao.queryUserByJob(job);
    }

    @Override
    public int saveFenPei(CustomCondition custom) {
        return marketDao.saveFenPei(custom);
    }


    /*
     *
     * @PACKAGE_NAME: com.warehouse_management.system.controller
     * @NAME: toPositionList
     * @USER: WanWenCheng
     * @DATE: 2022/10/2
     * @TIME: 20：56
     * @Description: 分页
     * */
    @Override
    public PageModel<Custom> PageJobPosition(Custom custom, PageModel<Custom> pageModel) {
        pageModel.setPageNum(pageModel.getPageNum()<=0?1:pageModel.getPageNum());
        pageModel.setPageSize(pageModel.getPageSize()<=0?3:pageModel.getPageSize());

        PageHelper.startPage(pageModel.getPageNum(),pageModel.getPageSize());
        List<Custom> customList = marketDao.queryAllCustom();

        PageInfo<Custom> pageInfo = new PageInfo<>(customList);

        pageModel.setTotalPage(pageInfo.getPages());
        pageModel.setTotalRows(pageInfo.getTotal());
        pageModel.setData(customList);
        return pageModel;
    }

    @Override
    public int AddCustom(CustomCondition customCondition) {
        return marketDao.AddCustom(customCondition);
    }


}
